//
//  LYEmoticonPopView.swift
//  EmoticonKeyboard
//
//  Created by liuerying on 16/5/31.
//  Copyright © 2016年 liuerying. All rights reserved.
//

import UIKit

class LYEmoticonPopView: UIView {

    @IBOutlet weak var emoticonBtn: LYEmoticonButton!
    
    class func loadPopView()-> LYEmoticonPopView{
    
        let pop = NSBundle.mainBundle().loadNibNamed("LYEmoticonPopView", owner: nil, options: nil).last as! LYEmoticonPopView
        
        return pop
    }
    
    func show(btn: LYEmoticonButton){
    
        let window = UIApplication.sharedApplication().windows.last!
        
        if self.superview == nil{
        
            window.addSubview(self)
        }
        self.hidden = false
        
        //转换坐标系
        let rect = btn.superview!.convertRect(btn.frame, toView:window)
        
        //设置fram
        center.x = CGRectGetMidX(rect)
        frame.origin.y = CGRectGetMaxY(rect) - bounds.height
        
//        emoticonBtn.emoticon = btn.emoticon
        
        emoticonBtn.emoticon = btn.emoticon
    
    }
    
    func dismissAfter(){
    
        let time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(Double(NSEC_PER_SEC)*0.2))
   
        dispatch_after(time_t, dispatch_get_main_queue()) { 
            self.hidden = true
        }
    }
}
